<template>
    <div class="outmain ba_f heighthv pad_20 bor_rad5">
        <div class="shuju_title mar_b20">
            <div class="shuju_title_text">
                <span>签到列表</span>
            </div>
        </div>
        <div class="tabledata mar_t20">
            <el-table
                    :data="list"
                    v-loading="listLoading"
                    :element-loading-text="elementLoadingText"
                    stripe
                    style="width: 100%"
                    class="tablecenter"
            >
                <el-table-column  label="用户名">
                    <template slot-scope="scope">
                        <div class="flex-center pad_tb_10">
                            <div class=""><img class="namelogo"  v-bind:src="scope.row.portrait"/></div>
                            <div class="flex-col mar_l15">
                                <div class="overflowlnr">{{ scope.row.userName }}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column  prop="userTel" label="手机号" ></el-table-column>
                <el-table-column prop="newTime" label="最新签到时间" > </el-table-column>
                <el-table-column prop="weekNum" label="本周签到次数"></el-table-column>
                <el-table-column prop="allNum" label="总签到次数"></el-table-column>
<!--                <el-table-column label="操作" width="180">-->
<!--                    <template slot-scope="scope">-->
<!--                        <el-button size="mini" type="text" @click="handleEdit(scope.row.id)" class="seebtn">签到记录</el-button>-->
<!--                    </template>-->
<!--                </el-table-column>-->
            </el-table>
            <el-pagination
                    background
                    layout="prev, pager, next"
                    :total="page.total"
                    :page-size="page.pagesize"
                    :current-page.sync='page.currentPage'
                    @current-change="handleCurrentChange">
            </el-pagination>
<!--            <edit ref="edit" @fetchData="fetchData"></edit>-->
        </div>
    </div>
</template>
<script>
    import {signList,modifyCoupon} from "@/api/plug";

    export default {
        created() {
            this.fetchData();
            if (this.$route.query.days) {
                this.days = this.$route.query.days
                this.fetchData();
            }
        },
        data() {
            return {
                list: [],
                listLoading: true,
                selectRows: "",
                elementLoadingText: "正在加载...",
                page: {
                    total: 0,
                    size: 10,
                    currentPage: 1,
                },
                days:'',
            }
        },
        methods: {
            async fetchData() {
                this.listLoading = true;
                const {data, count} = await signList({page: this.page.currentPage,days:this.days});
                this.list = data;
                this.page.total = count;
                this.listLoading = false;
            },
            handleCurrentChange(val) {
                this.page.currentPage = val;
                this.fetchData();
            },
            onSearch(){
                this.fetchData();
            },
            async changeSwitch(row) {
                const {msg} = await modifyCoupon({id: row.id, display: row.display,type:1});
                this.$baseMessage(msg, "success");
                this.fetchData();
            },
            handleDelete(row) {
                if (row.id) {
                    this.$baseConfirm("你确定要删除当前项吗", null, async () => {
                        const {msg} = await modifyCoupon({id: row.id,type:2});
                        this.$baseMessage(msg, "success");
                        this.fetchData();
                    });
                } else {
                    if (this.selectRows.length > 0) {
                        const id = this.selectRows.map((item) => item.id);
                        this.$baseConfirm("你确定要删除选中项吗", null, async () => {
                            const {msg} = await modifyCoupon({id,type:2});
                            this.$baseMessage(msg, "success");
                            this.fetchData();
                        });
                    } else {
                        this.$baseMessage("未选中任何行", "error");
                        return false;
                    }
                }
            },
            handleEdit(row) {
                if (row.id) {
                    this.$router.push(`/signinrecord?id=${row.id}`);
                } else {
                    // this.$router.push({path: 'addobject'})
                }
            },
        }
    }
</script>
